Repository navigation
fix(65069): preserve contextual types for array-destructured parameter defaults - #65070
Timur Vural (timurzvural) wants to merge 1 commit into
Conversation
…r defaults Skip padTupleType when the parameter already has a contextual type, matching the object-pattern guard for microsoft#64974. Also apply the same guard to padObjectLiteralType so object `= {}` defaults keep working on the same path. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
🟢 Approval recommended
The change preserving contextual types in destructured parameter defaults has no active review issues.
No open issues 🎉
What changed in this PR
Fixes #65069 by preserving contextual types for array-destructured parameter defaults in the native TypeScript checker. The same guard also addresses object defaults from #64974.
Changes:
- Skip tuple and object padding when the parameter has a contextual type.
- Add regression cases for object defaults, array defaults, callbacks, and nested/rest destructuring.
- Update type, symbol, and diagnostic baselines.
| File | Description |
|---|---|
tsc/testdata/tests/cases/compiler/objectBindingPatternDefaultMissingElements.ts |
Adds contextual-typing regression cases. |
tsc/testdata/baselines/reference/compiler/objectBindingPatternDefaultMissingElements.types |
Records preserved binding-element types. |
tsc/testdata/baselines/reference/compiler/objectBindingPatternDefaultMissingElements.symbols |
Records symbols for the added cases. |
tsc/testdata/baselines/reference/compiler/objectBindingPatternDefaultMissingElements.errors.txt |
Records expected assignment errors that verify contextual typing. |
tsc/internal/checker/checker.go |
Guards object and tuple padding with a contextual-type check. |
Review effort: Balanced
|
TypeScript Bot (@typescript-bot) test it |
|
Hey Ryan Cavanaugh (@RyanCavanaugh), the results of running the DT tests are ready. Everything looks the same! |
|
Ryan Cavanaugh (@RyanCavanaugh) Here are the results of running the user tests with tsc comparing Everything looks good! |
|
Ryan Cavanaugh (@RyanCavanaugh) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Ryan Cavanaugh (@RyanCavanaugh) Here are the results of running the top 400 repos with tsc comparing Everything looks good! |
Fixes #65069.
Bug
In 7.1, a destructured parameter with a default like
= []loses its contextual type and reportsTS7031on binding elements. The object form (= {}) is #64974; this PR covers the array form and also guards object padding the same way.Fix
In
checkDeclarationInitializer, only callpadTupleType/padObjectLiteralTypewhengetContextualTypeForVariableLikeDeclaration(root, ContextFlagsNone) == nil. Padding inventsany-typed missing elements and must not override a contextual parameter type.Tests
Extended
objectBindingPatternDefaultMissingElements.ts(and baselines) with array/= []cases from #65069 and an object/= {}case.Related
= []default loses its contextual type (TS7031) #65069= {}default loses its contextual type (TS7031) #64974 (open fix(64974): fix contextual typing for destructured parameter defaults #64978 only guards objects today)AI assistance disclosure
This PR was authored with assistance from Cursor Agent. I have read and understand the change and am prepared to discuss and revise it in review.